package com.hbu.product.hbumallproduct.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbu.common.TO.es.SkuEsModel;
import com.hbu.common.utils.PageUtils;
import com.hbu.common.utils.Query;
import com.hbu.product.hbumallproduct.dao.SkuSaleAttrValueDao;
import com.hbu.product.hbumallproduct.entity.SkuSaleAttrValueEntity;
import com.hbu.product.hbumallproduct.service.SkuSaleAttrValueService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @author 90458
 */
@Service("skuSaleAttrValueService")
public class SkuSaleAttrValueServiceImpl extends ServiceImpl<SkuSaleAttrValueDao, SkuSaleAttrValueEntity> implements SkuSaleAttrValueService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SkuSaleAttrValueEntity> page = this.page(
                new Query<SkuSaleAttrValueEntity>().getPage(params),
                new QueryWrapper<SkuSaleAttrValueEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SkuEsModel.Attr> getAttrList(Long skuId) {
        List<SkuSaleAttrValueEntity> attrList = baseMapper.getAttrList(skuId);
        return attrList.stream().map(attrSource -> {
            SkuEsModel.Attr attrs = new SkuEsModel.Attr();
            BeanUtils.copyProperties(attrSource, attrs);
            return attrs;
        }).collect(Collectors.toList());
    }

}